package dhm.com.hpx.adapter;

import android.content.Context;
import android.graphics.Color;
import android.support.annotation.NonNull;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;

import java.util.ArrayList;
import java.util.List;

import dhm.com.hpx.R;
import dhm.com.hpx.base.netWork.Constant;
import dhm.com.hpx.entity.DynamicListaBean;
import dhm.com.hpx.entity.FabulousVideoBean;
import dhm.com.hpx.entity.FavoriteArticleBean;
import dhm.com.hpx.entity.GetUserInfoBean;
import dhm.com.hpx.utils.SpUtils;

import static dhm.com.hpx.utils.UIUtils.getColor;

/**
 * Created by admin
 * 2019/4/29
 * 所有订单适配器
 */
public class MineCardAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private Context context;


    private GetUserInfoBean getUserInfoBean;


    List<DynamicListaBean.DataBean> list = new ArrayList<>();
    List<FabulousVideoBean.DataBean> list2=new ArrayList<>();
    List<FavoriteArticleBean.DataBean> list3=new ArrayList<>();
    private int type = 1;
    String uids;
    String uid;

    public void setGetUserInfoBean(GetUserInfoBean getUserInfoBean) {
        this.getUserInfoBean = getUserInfoBean;
        notifyDataSetChanged();
    }

    public void setList(List<DynamicListaBean.DataBean> list) {
        this.list = list;
        notifyDataSetChanged();
    }

    public void setList2(List<FabulousVideoBean.DataBean> list2) {
        this.list2 = list2;
        notifyDataSetChanged();
    }

    public void setList3(List<FavoriteArticleBean.DataBean> list3) {
        this.list3 = list3;
        notifyDataSetChanged();
    }

    public MineCardAdapter(Context context, String uid) {
        this.context = context;
        this.uid=uid;
        uids = SpUtils.getString(context, "uid");
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        if (i == 0) {
            View view = LayoutInflater.from(context).inflate(R.layout.item_minecardup, null);
            ViewHolder viewHolder1 = new ViewHolder(view);
            return viewHolder1;
        } else {
            View view = LayoutInflater.from(context).inflate(R.layout.item_maincarddown, null);
            View2Holder viewHolder = new View2Holder(view);
            return viewHolder;
        }
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, final int i) {
        if (i == 0) {
            ViewHolder vh = (ViewHolder) viewHolder;
            if (getUserInfoBean != null) {

                if (uid.equals(uids)){
                    vh.text.setVisibility(View.VISIBLE);
                }else {
                    vh.text.setVisibility(View.GONE);
                }
                vh.image.setImageURI(Constant.PATH+ getUserInfoBean.getData().getHeadsmall());
                vh.nick.setText(getUserInfoBean.getData().getUser_nickname());
                vh.zhiye.setText(getUserInfoBean.getData().getOccupation());
                vh.addr.setText(getUserInfoBean.getData().getProvince()+ getUserInfoBean.getData().getCity()+ getUserInfoBean.getData().getArea());
                vh.introduct.setText(getUserInfoBean.getData().getIntro());
                vh.likenum.setText(getUserInfoBean.getData().getFollowCount()+"");
                vh.likednum.setText(getUserInfoBean.getData().getFavoritesCount()+"");
                vh.fensinum.setText(getUserInfoBean.getData().getFansnum()+"");

                switch (getUserInfoBean.getData().getUserType()){
                    case 0:
                        vh.vip.setBackgroundResource(R.mipmap.vip_no);
                        break;
                    case 1:
                        vh.vip.setBackgroundResource(R.mipmap.vip_one);
                        break;
                    case 2:
                        vh.vip.setBackgroundResource(R.mipmap.vip_two);
                        break;
                    case 3:
                        vh.vip.setBackgroundResource(R.mipmap.vip_three);
                        break;
                }


            }
        } else {
            final View2Holder vh = (View2Holder) viewHolder;
            LinearLayoutManager manager=new LinearLayoutManager(context);
            manager.setOrientation(LinearLayoutManager.VERTICAL);
            vh.recy.setLayoutManager(manager);
            switch (type) {
                case 1:
                    if (list!=null&&list.size()>0){
                        DynamicAdapter adapter=new DynamicAdapter(context);
                        adapter.setdeleteClick(new DynamicAdapter.OnClick() {
                            @Override
                            public void item(int posttion, View view) {
                                onClick.item(posttion,view);
                            }
                        });
                        vh.recy.setAdapter(adapter);
                        adapter.setList(list);
                    }

                    break;
                case 2:
                    if (list2!=null&&list2.size()>0){
                        MessageVideoadapter videoadapter=new MessageVideoadapter(context);
                        videoadapter.setaddClick(new MessageVideoadapter.OnIntentClick() {
                            @Override
                            public void item(int position) {

                            }
                        });
                        videoadapter.setdeleteClick(new MessageVideoadapter.OnClick() {
                            @Override
                            public void item(int posttion) {

                            }
                        });
                        vh.recy.setAdapter(videoadapter);

                        videoadapter.setList(list2);
                    }
                    break;
                case 3:
                    if (list3!=null&&list3.size()>0){
                        MessageColletArticleadapter articleadapter=new MessageColletArticleadapter(context);
                        articleadapter.setaddClick(new MessageColletArticleadapter.OnIntentClick() {
                            @Override
                            public void item(int position) {

                            }
                        });
                        articleadapter.setdeleteClick(new MessageColletArticleadapter.OnClick() {
                            @Override
                            public void item(int posttion) {

                            }
                        });
                        vh.recy.setAdapter(articleadapter);
                        articleadapter.setList(list3);
                    }
                    break;
                default:
            }

            vh.dongtai.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    type=1;
                    vh.text_dongtai.setTextColor(getColor(R.color.main));
                    vh.line_dongtai.setVisibility(View.VISIBLE);
                    vh.text_zanguo.setTextColor(Color.parseColor("#666666"));
                    vh.text_collect.setTextColor(Color.parseColor("#666666"));
                    vh.line_zanguo.setVisibility(View.INVISIBLE);
                    vh.line_collect.setVisibility(View.INVISIBLE);
                    onIntentClick.item(type);
                }
            });

            vh.zanguo.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    type=2;
                    vh.text_zanguo.setTextColor(getColor(R.color.main));
                    vh.line_zanguo.setVisibility(View.VISIBLE);
                    vh.text_dongtai.setTextColor(Color.parseColor("#666666"));
                    vh.text_collect.setTextColor(Color.parseColor("#666666"));
                    vh.line_dongtai.setVisibility(View.INVISIBLE);
                    vh.line_collect.setVisibility(View.INVISIBLE);
                    onIntentClick.item(type);
                }
            });

            vh.collection.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    type=3;
                    vh.text_collect.setTextColor(getColor(R.color.main));
                    vh.line_collect.setVisibility(View.VISIBLE);
                    vh.text_zanguo.setTextColor(Color.parseColor("#666666"));
                    vh.text_dongtai.setTextColor(Color.parseColor("#666666"));
                    vh.line_zanguo.setVisibility(View.INVISIBLE);
                    vh.line_dongtai.setVisibility(View.INVISIBLE);
                    onIntentClick.item(type);
                }
            });


        }
    }

    @Override
    public int getItemViewType(int position) {
        return position;
    }

    @Override
    public int getItemCount() {
        return 2;
    }

    class ViewHolder extends RecyclerView.ViewHolder {

        public SimpleDraweeView image;
        public TextView nick;
        public TextView text;
        public TextView likenum;
        public TextView fensinum;
        public TextView likednum;
        public TextView zhiye;
        public TextView addr;
        public TextView introduct;
        public ImageView vip;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            vip = itemView.findViewById(R.id.vip);
            image = itemView.findViewById(R.id.image);
            nick = itemView.findViewById(R.id.nick);
            text = itemView.findViewById(R.id.text);
            likenum = itemView.findViewById(R.id.likenum);
            fensinum = itemView.findViewById(R.id.fensinum);
            likednum = itemView.findViewById(R.id.likednum);
            zhiye = itemView.findViewById(R.id.zhiye);
            addr = itemView.findViewById(R.id.addr);
            introduct = itemView.findViewById(R.id.introduct);
        }
    }

    class View2Holder extends RecyclerView.ViewHolder {

        public LinearLayout dongtai;
        public TextView text_dongtai;
        public TextView line_dongtai;
        public LinearLayout zanguo;
        public TextView text_zanguo;
        public TextView line_zanguo;
        public LinearLayout collection;
        public TextView text_collect;
        public TextView line_collect;
        public RecyclerView recy;

        public View2Holder(@NonNull View itemView) {
            super(itemView);
            dongtai = itemView.findViewById(R.id.dongtai);
            text_dongtai = itemView.findViewById(R.id.text_dongtai);
            line_dongtai = itemView.findViewById(R.id.line_dongtai);
            zanguo = itemView.findViewById(R.id.zanguo);
            text_zanguo = itemView.findViewById(R.id.text_zanguo);
            line_zanguo = itemView.findViewById(R.id.line_zanguo);
            collection = itemView.findViewById(R.id.collection);
            text_collect = itemView.findViewById(R.id.text_collect);
            line_collect = itemView.findViewById(R.id.line_collect);
            recy = itemView.findViewById(R.id.recy);
        }
    }
    private OnClick onClick;
    public void setdeleteClick(OnClick onClick) {
        this.onClick = onClick;
    }
    public interface OnClick{
        void item(int posttion,View view);
    }

    private OnIntentClick onIntentClick;

    public void setaddClick(OnIntentClick onClick) {
        this.onIntentClick = onClick;
    }

    public interface OnIntentClick {
        void item(int type);
    }


}

